// home组件的小模块，一个模块就是一个小的store
import { reqCategoryList, reqBannerList, reqFloorList } from "@/api"

export default {
    state: {
        categoryList: [],
        bannerList: [],
        floorList:[]
    },
    mutations: {
        UPDATE_CATEGORYLIST(state, categoryList) {
            // console.log(categoryList);
            state.categoryList = categoryList
        },
        UPDATE_BANNERLIST(state,bannerList) {
            state.bannerList = bannerList
        },
        UPDATE_FLOORLIST(state, floorList) {
            state.floorList = floorList
        }
    },
    actions: {
        async getCategoryList({commit}) {
            const res = await reqCategoryList()
            // console.log(res,'.....');
            if (res.code === 200) {
                commit('UPDATE_CATEGORYLIST',res.data.slice(0,15))
            }
        },
        async getBannerList({commit}) {
            const res = await reqBannerList()
            if (res.code === 200) {
                commit('UPDATE_BANNERLIST',res.data)
            }
        },
        async getFloorList({ commit }) {
            const res = await reqFloorList()
            if (res.code === 200) {
                commit('UPDATE_FLOORLIST',res.data)
            }
        }
    },
    getters: {
        newA(state) {
            return state.a+state.b
        }
    }
}